package leetcode;

//给定一个二叉树，找出其最大深度。
//二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。
//说明: 叶子节点是指没有子节点的节点。

public class problems_104 {

    public static void main(String[] arge) {
        TreeNode A1 = new TreeNode(1);
        TreeNode A2 = new TreeNode(2);
        TreeNode A3 = new TreeNode(2);
        TreeNode A4 = new TreeNode(3);
        TreeNode A5 = new TreeNode(4);
        TreeNode A6 = new TreeNode(4);
        TreeNode A7 = new TreeNode(3);
        A1.left = A2;
        A1.right = A3;
        A2.left = A4;
        A2.right = A5;
        A3.left = A6;
        A3.right = A7;
        int ret = new Solution().maxDepth(A1);
        System.out.println(ret);
    }
    static class Solution {
        public int maxDepth(TreeNode root) {
            return checkNode(root, 0);
        }
        private int checkNode(TreeNode node, int loop){
            if (null == node) return loop;
            return Math.max(checkNode(node.left, loop+1), checkNode(node.right, loop+1));
        }
    }
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) { val = x; }
    }
}
